import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AmapProvider } from "../../providers/amap/amap";
/**
 * Generated class for the MapingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-maping',
  templateUrl: 'maping.html',
})
export class MapingPage {

  private inputViewModel = {
    times: "1"
  }

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public amap: AmapProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MapingPage');
    this.loadMap();
  }

  //加载地图
  loadMap() {
    let map = this.amap.initMap("container");
    this.amap.initMapPlugins(map).then(() => {
      this.amap.initGeolocation(map).then(success => {
        //设置当前定位坐标
        map.setCenter(success['position']);
        //添加标注
        let marker = this.amap.initMarker(success['position']['lng'], success['position']['lat']);
        marker.setMap(map);
      }, fail => {

      });
    });
  }
}
